// https://leetcode.cn/problems/tvdfij/description/


func pivotIndex(nums []int) int {
    n := len(nums)
	pre_sum := make([]int, n)
	pre_sum[0] = 0
	post_sum := make([]int, n)
	post_sum[n - 1] = 0
	for i := 1; i < n; i++ {
		pre_sum[i] = pre_sum[i - 1] + nums[i - 1]
		post_sum[n - i - 1] = post_sum[n - i] + nums[n - i]
	}
	for i := 0; i < n; i++ {
		if pre_sum[i] == post_sum[i] {
			return i
		}
	}
	return -1
}